#include <stdio.h>

int main(int argc, char const *argv[])
{
    if(argc != 3)
    {
        printf( "Pls input ./a.out <dst file name> <string to be written>\n" );
        return -1;
    }

    FILE *fp = fopen( argv[1], "a" );
    if ( NULL == fp )
    {
        printf( "Fail to open file %s", argv[1] );
        return -1;
    }

    const char *pCh = argv[2];
    int iCounter = 0;
    while( *pCh != '\0')
    {
        fputc( *pCh, fp );
        ++pCh;
        ++iCounter;
    }
    
    printf( "Success to write string \"%s\"(total %d chars) to file < %s >\n", 
            argv[2], iCounter, argv[1] );

    fclose(fp);
    
    return 0;
}

/*
知识要点:
    const char *pCh: pCh指针指向的内容不能更改, 对应main函数的参数 char const *argv[]
    在将 pCh 指向的字符串写入 fp 时, 每次写入一个字符, 需要将 pCh 向后挪一位, 而 fputc 函数自动将文件写入位置向后挪一位.
*/